home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / gltron / skybox.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-09  |  2.1 KB  |  69 lines  |  [TEXT/CWIE]

  1. #include "gltron.h"
  2.  
  3. void enableSkyboxTexture() {
  4.   glEnable(GL_TEXTURE_2D);
  5. }
  6.  
  7. void disableSkyboxTexture() {
  8.   glDisable(GL_TEXTURE_2D);
  9. }
  10.  
  11. void bindSkyboxTexture(int index) {
  12.   glBindTexture(GL_TEXTURE_2D, game->screen->textures[ TEX_SKYBOX + index ]);
  13. }
  14.  
  15. void skybox() {
  16.   /* 
  17.      matrices are: 
  18.      projection: perspective projection 
  19.      modelview: identity
  20.   */
  21.   
  22.   /* these are the values for y == up, x == front */
  23.   /* 
  24.   float sides[6][4][3] = {
  25.     { { 1, -1, -1 }, { 1, -1, 1 }, { 1, 1, 1 },  { 1, 1, -1 } }, // front
  26.     { { 1, 1, -1 }, { 1, 1, 1 }, { -1, 1, 1 }, { -1, 1, -1 } }, // top
  27.     { { -1, -1, -1 }, { 1, -1, -1 },  { 1, 1, -1 }, { -1, 1, -1 } }, // left
  28.     { { 1, -1, 1 }, { -1, -1, 1 }, { -1, 1, 1 }, { 1, 1, 1 } }, // right
  29.     { { -1, -1, -1 }, { 1, -1, -1 }, { 1, -1, 1 }, { -1, -1, 1 } }, // botton
  30.     { { -1, -1, 1 }, { -1, -1, -1 }, { -1, 1, -1 }, { -1, 1, a1 } } // back
  31.   };
  32.   */
  33.  
  34.   /* these values are for z == up, x == front */
  35.   float sides[6][4][3] = {
  36.     { { 1, 1, -1 }, { 1, -1, -1 }, { 1, -1, 1 },  { 1, 1, 1 } }, // front
  37.     { { 1, 1, 1 }, { -1, 1, 1 }, { -1, -1, 1 }, { 1, -1, 1 } }, // top
  38.     { { -1, 1, -1 }, { 1, 1, -1 },  { 1, 1, 1 }, { -1, 1, 1 } }, // left
  39.     { { 1, -1, -1 }, { -1, -1, -1 }, { -1, -1, 1 }, { 1, -1, 1 } }, // right
  40.     { { -1, 1, -1 }, { -1, -1, -1 }, { 1, -1, -1 }, { 1, 1, -1 } }, // botton
  41.     { { -1, -1, -1 }, { -1, 1, -1 }, { -1, 1, 1 }, { -1, -1, 1 } } // back
  42.   };
  43.  
  44.   float colors[6][3] = { 
  45.     { 1, 1, 0 }, { 1, 0.5, 0.5 }, { 0.5, 1, 1 }, 
  46.     { 0, 1, 1 }, { 1, 0, 1 }, { 0.5, 1, 0.5 }
  47.   };
  48.     
  49.   float uv[4][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } };
  50.   int i, j;
  51.   float d = game->settings->grid_size * 3;
  52.  
  53.   glEnable(GL_TEXTURE_2D);
  54.   glDepthMask(GL_FALSE);
  55.   glColor3f(1.0, 1.0, 1.0);
  56.   for(i = 0; i < 6; i++) {
  57.     bindSkyboxTexture(i);
  58.     glBegin(GL_QUADS);
  59.     /* debug:  glColor3fv(colors[i]); */
  60.     for(j = 0; j < 4; j++) {
  61.       glTexCoord2fv( uv[j] );
  62.       glVertex3f( sides[i][j][0] * d, sides[i][j][1] * d, sides[i][j][2] * d );
  63.     }
  64.     glEnd();
  65.   }
  66.   glDisable(GL_TEXTURE_2D);
  67.   glDepthMask(GL_TRUE);
  68. }
  69.